In [1]:
import json 
import numpy as np
import os
import pandas as pd
import plotly.express as px
import plotly
plotly.offline.init_notebook_mode()
In [2]:
def get_mean_history(histories):
    return np.mean(histories, axis=0)


def get_std_history(histories):
    return np.std(histories, axis=0)

Schwefel

In [3]:
problem = "Schwefel"
path = f"./{problem}/results"

dict_for_show_50_Schwefel = dict()
params_list_50 = []
history_list_50 = []
iteration_list_50 = []
std_list_50 = []
dict_for_show_100_Schwefel = dict()
params_list_100 = []
history_list_100 = []
iteration_list_100 = []
std_list_100 = []
dict_for_show_200_Schwefel = dict()
params_list_200 = []
history_list_200 = []
iteration_list_200 = []
std_list_200 = []

for filename in os.listdir(path):
    full_path = path + "/" + filename
    with open(full_path) as file:
        results = json.load(file)
        if results["number_of_variables"] == 50:
        
            params = f'ps={results["population_size"]}_ss={results["selection_size"]}_m={results["mutation"]}_mp={results["mutation_probability"]}_cr={results["clone_rate"]}_rc={results["random_cells_number"]}'
            iteration_num = len(results['results'][0])
            params_list_50 += [params]*iteration_num
            history_list_50 += list(get_mean_history(results['results']))
            iteration_list_50 += range(iteration_num)
            std_list_50 += list(get_std_history(results['results']))
            
            
        if results["number_of_variables"] == 100:
        
            params = f'ps={results["population_size"]}_ss={results["selection_size"]}_m={results["mutation"]}_mp={results["mutation_probability"]}_cr={results["clone_rate"]}_rc={results["random_cells_number"]}'
            
            iteration_num = len(results['results'][0])
            params_list_100 += [params]*iteration_num
            history_list_100 += list(get_mean_history(results['results']))
            iteration_list_100 += range(iteration_num)
            std_list_100 += list(get_std_history(results['results']))
            
        if results["number_of_variables"] == 200:
            params = f'ps={results["population_size"]}_ss={results["selection_size"]}_m={results["mutation"]}_mp={results["mutation_probability"]}_cr={results["clone_rate"]}_rc={results["random_cells_number"]}'
            
            iteration_num = len(results['results'][0])
            params_list_200 += [params]*iteration_num
            history_list_200 += list(get_mean_history(results['results']))
            iteration_list_200 += range(iteration_num)
            std_list_200 += list(get_std_history(results['results']))


dict_for_show_100_Schwefel.update({'params': params_list_100, 
                          'mean max fitness': history_list_100, 
                          'iteration': iteration_list_100, 
                          'std': std_list_100})
dict_for_show_50_Schwefel.update({'params': params_list_50, 
                          'mean max fitness': history_list_50, 
                          'iteration': iteration_list_50, 
                          'std': std_list_50})
dict_for_show_200_Schwefel.update({'params': params_list_200, 
                          'mean max fitness': history_list_200, 
                          'iteration': iteration_list_200, 
                          'std': std_list_200})
In [4]:
pd.options.plotting.backend = "plotly"
df_100_Schwefel = pd.DataFrame(dict_for_show_100_Schwefel)

fig = px.line(df_100_Schwefel, x="iteration", y="mean max fitness", 
              color='params',  log_y=True, title="Schwefel 100") # error_y="std",

fig.show()
In [5]:
pd.options.plotting.backend = "plotly"
df_50_Schwefel = pd.DataFrame(dict_for_show_50_Schwefel)

fig = px.line(df_50_Schwefel, x="iteration", y="mean max fitness", color='params',  
              log_y=True, title="Schwefel 50") # error_y="std",

fig.show()
In [6]:
pd.options.plotting.backend = "plotly"
df_200_Schwefel = pd.DataFrame(dict_for_show_200_Schwefel)

fig = px.line(df_200_Schwefel, x="iteration", y="mean max fitness", color='params',  
              log_y=True, title="Schwefel 200") # error_y="std",

fig.show()
In [7]:
problem = "Schwefel"
path = f"./{problem}/results_elite"

dict_for_show_50_Schwefel_elite = dict()
params_list_50 = []
history_list_50 = []
iteration_list_50 = []
std_list_50 = []
dict_for_show_100_Schwefel_elite = dict()
params_list_100 = []
history_list_100 = []
iteration_list_100 = []
std_list_100 = []
dict_for_show_200_Schwefel_elite = dict()
params_list_200 = []
history_list_200 = []
iteration_list_200 = []
std_list_200 = []

for filename in os.listdir(path):
    full_path = path + "/" + filename
    if "ipynb_checkpoints" in full_path:
        continue
    with open(full_path) as file:
        results = json.load(file)
        if results["number_of_variables"] == 50:
        
            params = f'ps={results["population_size"]}_ss={results["selection_size"]}_mutation={results["push"]:.2f},{results["pull"]:.2f},{results["random"]:.2f}_mp={results["mutation_probability"]}_cr={results["clone_rate"]}_rc={results["random_cells_number"]}'
            iteration_num = len(results['results'][0])
            params_list_50 += [params]*iteration_num
            history_list_50 += list(get_mean_history(results['results']))
            iteration_list_50 += range(iteration_num)
            std_list_50 += list(get_std_history(results['results']))
            
            
        if results["number_of_variables"] == 100:
        
            params = f'ps={results["population_size"]}_ss={results["selection_size"]}_mutation={results["push"]:.2f},{results["pull"]:.2f},{results["random"]:.2f}_mp={results["mutation_probability"]}_cr={results["clone_rate"]}_rc={results["random_cells_number"]}'
            
            iteration_num = len(results['results'][0])
            params_list_100 += [params]*iteration_num
            history_list_100 += list(get_mean_history(results['results']))
            iteration_list_100 += range(iteration_num)
            std_list_100 += list(get_std_history(results['results']))
        if results["number_of_variables"] == 200:
        
            params = f'ps={results["population_size"]}_ss={results["selection_size"]}_mutation={results["push"]:.2f},{results["pull"]:.2f},{results["random"]:.2f}_mp={results["mutation_probability"]}_cr={results["clone_rate"]}_rc={results["random_cells_number"]}'
            
            iteration_num = len(results['results'][0])
            params_list_200 += [params]*iteration_num
            history_list_200 += list(get_mean_history(results['results']))
            iteration_list_200 += range(iteration_num)
            std_list_200 += list(get_std_history(results['results']))


dict_for_show_100_Schwefel_elite.update({'params': params_list_100, 
                          'mean max fitness': history_list_100, 
                          'iteration': iteration_list_100, 
                          'std': std_list_100})
dict_for_show_50_Schwefel_elite.update({'params': params_list_50, 
                          'mean max fitness': history_list_50, 
                          'iteration': iteration_list_50, 
                          'std': std_list_50})
dict_for_show_200_Schwefel_elite.update({'params': params_list_200, 
                          'mean max fitness': history_list_200, 
                          'iteration': iteration_list_200, 
                          'std': std_list_200})
In [8]:
pd.options.plotting.backend = "plotly"
df_100_Schwefel_elite = pd.DataFrame(dict_for_show_100_Schwefel_elite)

fig = px.line(df_100_Schwefel_elite, x="iteration", y="mean max fitness", 
              color='params',  log_y=True, title="Schwefel Elite 100") # error_y="std",

fig.show()
In [9]:
pd.options.plotting.backend = "plotly"
df_50_Schwefel_elite = pd.DataFrame(dict_for_show_50_Schwefel_elite)

fig = px.line(df_50_Schwefel_elite, x="iteration", y="mean max fitness", color='params',  
              log_y=True, title="Schwefel Elite 50") # error_y="std",

fig.show()
In [10]:
pd.options.plotting.backend = "plotly"
df_200_Schwefel_elite = pd.DataFrame(dict_for_show_200_Schwefel_elite)

fig = px.line(df_200_Schwefel_elite, x="iteration", y="mean max fitness", 
              color='params',  log_y=True, title="Schwefel Elite 200") # error_y="std",

fig.show()
In [11]:
df_100_Schwefel_sorted = df_100_Schwefel.sort_values(by=["iteration", "mean max fitness"], ascending=[False, True])

df_100_Schwefel_elite_sorted = df_100_Schwefel_elite.sort_values(by=["iteration", "mean max fitness"], ascending=[False, True])

df_50_Schwefel_sorted = df_50_Schwefel.sort_values(by=["iteration", "mean max fitness"], ascending=[False, True])

df_50_Schwefel_elite_sorted = df_50_Schwefel_elite.sort_values(by=["iteration", "mean max fitness"], ascending=[False, True])

df_200_Schwefel_sorted = df_200_Schwefel.sort_values(by=["iteration", "mean max fitness"], ascending=[False, True])

df_200_Schwefel_elite_sorted = df_200_Schwefel_elite.sort_values(by=["iteration", "mean max fitness"], ascending=[False, True])
In [12]:
best_100_Schwefel = list(df_100_Schwefel_sorted["params"][:3])
best_100_Schwefel_elite = list(df_100_Schwefel_elite_sorted["params"][:3])
best_50_Schwefel = list(df_50_Schwefel_sorted["params"][:3])
best_50_Schwefel_elite = list(df_50_Schwefel_elite_sorted["params"][:3])
best_200_Schwefel = list(df_200_Schwefel_sorted["params"][:3])
best_200_Schwefel_elite = list(df_200_Schwefel_elite_sorted["params"][:3])
In [13]:
dict_for_show_50_Schwefel_comp = dict()
params_list_50 = []
history_list_50 = []
iteration_list_50 = []
std_list_50 = []
dict_for_show_100_Schwefel_comp = dict()
params_list_100 = []
history_list_100 = []
iteration_list_100 = []
std_list_100 = []

dict_for_show_200_Schwefel_comp = dict()
params_list_200 = []
history_list_200 = []
iteration_list_200 = []
std_list_200 = []

problem = "Schwefel"
path = f"./{problem}/results_elite"



for filename in os.listdir(path):
    full_path = path + "/" + filename
    if "ipynb_checkpoints" in full_path:
        continue
    with open(full_path) as file:
        results = json.load(file)
        if results["number_of_variables"] == 50:
        
            params = f'ps={results["population_size"]}_ss={results["selection_size"]}_mutation={results["push"]:.2f},{results["pull"]:.2f},{results["random"]:.2f}_mp={results["mutation_probability"]}_cr={results["clone_rate"]}_rc={results["random_cells_number"]}'
            
            if params in best_50_Schwefel_elite:
                iteration_num = len(results['results'][0])
                params_list_50 += [params + "_elite"]*iteration_num
                history_list_50 += list(get_mean_history(results['results']))
                iteration_list_50 += range(iteration_num)
                std_list_50 += list(get_std_history(results['results']))
            
            
        if results["number_of_variables"] == 100:
        
            params = f'ps={results["population_size"]}_ss={results["selection_size"]}_mutation={results["push"]:.2f},{results["pull"]:.2f},{results["random"]:.2f}_mp={results["mutation_probability"]}_cr={results["clone_rate"]}_rc={results["random_cells_number"]}'
            if params in best_100_Schwefel_elite:
                iteration_num = len(results['results'][0])
                params_list_100 += [params + "_elite"]*iteration_num
                history_list_100 += list(get_mean_history(results['results']))
                iteration_list_100 += range(iteration_num)
                std_list_100 += list(get_std_history(results['results']))
                
        if results["number_of_variables"] == 200:
        
            params = f'ps={results["population_size"]}_ss={results["selection_size"]}_mutation={results["push"]:.2f},{results["pull"]:.2f},{results["random"]:.2f}_mp={results["mutation_probability"]}_cr={results["clone_rate"]}_rc={results["random_cells_number"]}'
            if params in best_200_Schwefel_elite:
                iteration_num = len(results['results'][0])
                params_list_200 += [params + "_elite"]*iteration_num
                history_list_200 += list(get_mean_history(results['results']))
                iteration_list_200 += range(iteration_num)
                std_list_200 += list(get_std_history(results['results']))




dict_for_show_100_Schwefel_comp.update({'params': params_list_100, 
                          'mean max fitness': history_list_100, 
                          'iteration': iteration_list_100, 
                          'std': std_list_100})
dict_for_show_50_Schwefel_comp.update({'params': params_list_50, 
                          'mean max fitness': history_list_50, 
                          'iteration': iteration_list_50, 
                          'std': std_list_50})

dict_for_show_200_Schwefel_comp.update({'params': params_list_200, 
                          'mean max fitness': history_list_200, 
                          'iteration': iteration_list_200, 
                          'std': std_list_200})



problem = "Schwefel"
path = f"./{problem}/results"

for filename in os.listdir(path):
    full_path = path + "/" + filename
    with open(full_path) as file:
        results = json.load(file)
        if results["number_of_variables"] == 50:
        
            params = f'ps={results["population_size"]}_ss={results["selection_size"]}_m={results["mutation"]}_mp={results["mutation_probability"]}_cr={results["clone_rate"]}_rc={results["random_cells_number"]}'
            if params in best_50_Schwefel:
                iteration_num = len(results['results'][0])
                params_list_50 += [params]*iteration_num
                history_list_50 += list(get_mean_history(results['results']))
                iteration_list_50 += range(iteration_num)
                std_list_50 += list(get_std_history(results['results']))
            
            
        if results["number_of_variables"] == 100:
        
            params = f'ps={results["population_size"]}_ss={results["selection_size"]}_m={results["mutation"]}_mp={results["mutation_probability"]}_cr={results["clone_rate"]}_rc={results["random_cells_number"]}'
            if params in best_100_Schwefel:
                iteration_num = len(results['results'][0])
                params_list_100 += [params]*iteration_num
                history_list_100 += list(get_mean_history(results['results']))
                iteration_list_100 += range(iteration_num)
                std_list_100 += list(get_std_history(results['results']))
                
        if results["number_of_variables"] == 200:
        
            params = f'ps={results["population_size"]}_ss={results["selection_size"]}_m={results["mutation"]}_mp={results["mutation_probability"]}_cr={results["clone_rate"]}_rc={results["random_cells_number"]}'
            if params in best_200_Schwefel:
                iteration_num = len(results['results'][0])
                params_list_200 += [params]*iteration_num
                history_list_200 += list(get_mean_history(results['results']))
                iteration_list_200 += range(iteration_num)
                std_list_200 += list(get_std_history(results['results']))
                

dict_for_show_100_Schwefel_comp.update({'params': params_list_100, 
                          'mean max fitness': history_list_100, 
                          'iteration': iteration_list_100, 
                          'std': std_list_100})
dict_for_show_50_Schwefel_comp.update({'params': params_list_50, 
                          'mean max fitness': history_list_50, 
                          'iteration': iteration_list_50, 
                          'std': std_list_50})

dict_for_show_200_Schwefel_comp.update({'params': params_list_200, 
                          'mean max fitness': history_list_200, 
                          'iteration': iteration_list_200, 
                          'std': std_list_200})
In [14]:
pd.options.plotting.backend = "plotly"
df_100_Schwefel_comp = pd.DataFrame(dict_for_show_100_Schwefel_comp)

fig = px.line(df_100_Schwefel_comp, x="iteration", y="mean max fitness", color='params', 
              log_y=True, title="Schwefel 100 - Best 3 comparison") # error_y="std",

fig.show()
In [15]:
pd.options.plotting.backend = "plotly"
df_100_Schwefel_comp = pd.DataFrame(dict_for_show_100_Schwefel_comp)

fig = px.line(df_100_Schwefel_comp, x="iteration", y="mean max fitness", color='params', 
            title="Schwefel 100 - Best 3 comparison") # error_y="std",

fig.show()
In [16]:
pd.options.plotting.backend = "plotly"
df_50_Schwefel_comp = pd.DataFrame(dict_for_show_50_Schwefel_comp)

fig = px.line(df_50_Schwefel_comp, x="iteration", y="mean max fitness", color='params', 
              log_y=True, title="Schwefel 50 - Best 3 comparison") # error_y="std",

fig.show()
In [17]:
pd.options.plotting.backend = "plotly"
df_50_Schwefel_comp = pd.DataFrame(dict_for_show_50_Schwefel_comp)

fig = px.line(df_50_Schwefel_comp, x="iteration", y="mean max fitness", color='params', 
               title="Schwefel 50 - Best 3 comparison") # error_y="std",

fig.show()
In [18]:
pd.options.plotting.backend = "plotly"
df_200_Schwefel_comp = pd.DataFrame(dict_for_show_200_Schwefel_comp)

fig = px.line(df_200_Schwefel_comp, x="iteration", y="mean max fitness", color='params', 
              log_y=True, title="Schwefel 200 - Best 3 comparison") # error_y="std",

fig.show()
In [19]:
pd.options.plotting.backend = "plotly"
df_200_Schwefel_comp = pd.DataFrame(dict_for_show_200_Schwefel_comp)

fig = px.line(df_200_Schwefel_comp, x="iteration", y="mean max fitness", color='params', 
              title="Schwefel 200 - Best 3 comparison") # error_y="std",

fig.show()
In [21]:
problem = "Schwefel"
path = f"./{problem}/results"

dict_for_show_Schwefel = dict()
params_list = []
history_list = []
iteration_list = []
std_list = []

for filename in os.listdir(path):
    full_path = path + "/" + filename
    if "ipynb_checkpoints" in full_path:
        continue
    with open(full_path) as file:
        results = json.load(file)
        if results["mutation"] != "random":
            continue
        if results["number_of_variables"] != 100:
            continue
        elite_same_1 = f'./{problem}/results_elite/clonal_selection_elite_{problem}_{results["number_of_variables"]}_{results["population_size"]}_{results["selection_size"]}_{1/3}_{1/3}_{1/3}_{results["mutation_probability"]}_{results["clone_rate"]}_{results["random_cells_number"]}.json'
        elite_same_2 = f'./{problem}/results_elite/clonal_selection_elite_{problem}_{results["number_of_variables"]}_{results["population_size"]}_{results["selection_size"]}_{1/2}_{1/2}_{0}_{results["mutation_probability"]}_{results["clone_rate"]}_{results["random_cells_number"]}.json'

        with open(elite_same_1) as elite_same_1_file:
            with open(elite_same_2) as elite_same_2_file:
                results_elite_1 = json.load(elite_same_1_file)
                results_elite_2 = json.load(elite_same_2_file)

                if list(get_mean_history(results['results']))[-1] > list(get_mean_history(results_elite_1['results']))[-1] \
                    or list(get_mean_history(results['results']))[-1] > list(get_mean_history(results_elite_2['results']))[-1]:
                    params = f'v={results["number_of_variables"]}_ps={results["population_size"]}_ss={results["selection_size"]}_m={results["mutation"]}_mp={results["mutation_probability"]}_cr={results["clone_rate"]}_rc={results["random_cells_number"]}'

                    iteration_num = len(results['results'][0])
                    params_list += [params]*iteration_num
                    history_list += list(get_mean_history(results['results']))
                    iteration_list += range(iteration_num)
                    std_list += list(get_std_history(results['results']))
                    
                if list(get_mean_history(results['results']))[-1] > list(get_mean_history(results_elite_1['results']))[-1]:
                  
                    params = f'v={results_elite_1["number_of_variables"]}_ps={results_elite_1["population_size"]}_ss={results_elite_1["selection_size"]}_m={results_elite_1["push"]:.2f},{results_elite_1["pull"]:.2f},{results_elite_1["random"]:.2f}_mp={results_elite_1["mutation_probability"]}_cr={results_elite_1["clone_rate"]}_rc={results_elite_1["random_cells_number"]}'

                    iteration_num = len(results_elite_1['results'][0])
                    params_list += [params]*iteration_num
                    history_list += list(get_mean_history(results_elite_1['results']))
                    iteration_list += range(iteration_num)
                    std_list += list(get_std_history(results_elite_1['results']))
                    
                if list(get_mean_history(results['results']))[-1] > list(get_mean_history(results_elite_2['results']))[-1]:
                  
                    params = f'v={results_elite_2["number_of_variables"]}_ps={results_elite_2["population_size"]}_ss={results_elite_2["selection_size"]}_m={results_elite_2["push"]:.2f},{results_elite_2["pull"]:.2f},{results_elite_2["random"]:.2f}_mp={results_elite_2["mutation_probability"]}_cr={results_elite_2["clone_rate"]}_rc={results_elite_2["random_cells_number"]}'

                    iteration_num = len(results_elite_2['results'][0])
                    params_list += [params]*iteration_num
                    history_list += list(get_mean_history(results_elite_2['results']))
                    iteration_list += range(iteration_num)
                    std_list += list(get_std_history(results_elite_2['results']))
                
                if params_list:
                    dict_for_show_Schwefel.update({'params': params_list, 
                                              'mean max fitness': history_list, 
                                              'iteration': iteration_list, 
                                              'std': std_list})
                    pd.options.plotting.backend = "plotly"
                    df_Schwefel = pd.DataFrame(dict_for_show_Schwefel)

                    fig = px.line(df_Schwefel, x="iteration", y="mean max fitness", color='params', 
                                  title="Schwefel elite best") # error_y="std",

                    fig.show()
                dict_for_show_Schwefel = dict()
                params_list = []
                history_list = []
                iteration_list = []
                std_list = []
                best_results = []
In [ ]:
pd.options.plotting.backend = "plotly"
df_Schwefel = pd.DataFrame(dict_for_show_Schwefel)

fig = px.line(df_Schwefel, x="iteration", y="mean max fitness", color='params', 
              title="Schwefel elite best") # error_y="std",

fig.show()
In [ ]: